package edu.psu.geovista.app.pcp.plot.control.tools;

import edu.psu.geovista.app.pcp.plot.gui.BasicPcpUI;
import edu.psu.geovista.app.pcp.plot.gui.PcpCanvas;
import edu.psu.geovista.app.pcp.plot.layer.ConfigInfo;
import edu.psu.geovista.app.plot.layer.Layer;

import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: jinchen
 * Date: Jun 29, 2003
 * Time: 4:30:40 PM
 * To change this template use Options | File Templates.
 */
public class PlotTool extends BasicTool{


    public PlotTool(BasicPcpUI ui) {
        super(ui);

    }

    public void setBGColor(Color color) {

        /*BackgroundLayer bgLayer =(BackgroundLayer)ui.getLayer(Layer.BACKGROUND_LAYER ) ;
        ConfigInfo cfgInfo=bgLayer.getConfigInfo() ;
        cfgInfo.setConfig(ConfigInfo.COLOR,color);
        bgLayer.paintLayer() ;*/
        PcpCanvas canvas = ui.getPlotCanvas();
        canvas.setBackground(color);

        this.repaintPlot() ;

    }

    public void erepaintPlot() {
    }
    /**
     *
     * @param target  defined in PlotConfig
     * @param key
     * @param value
     */
    public void setAConfigInfo(String target,String key, Object value) {
        Layer layer=null;
                 if(target.equals(ConfigInfo.TARGET_BACKGROUND) ){  //"background"
                     //no need Background layr any more, simply use PlotCanvas to serve the purpose
                     if(value instanceof Color){
                          Color color=(Color) value;
                          PcpCanvas canvas = ui.getPlotCanvas();
                          canvas.setBackground(color);
                          repaintPlot() ;
                     }
                     //layer =getLayer(Layer.BACKGROUND_LAYER ) ;
                 }
                 else if(target.equals(ConfigInfo.TARGET_AXIS) ){  //"axis"
                     //PlotCmd plotCmd=(PlotCmd)PlotConfig.this.getCmd(BasicCmd.PlotT );
                     layer= getLayer(Layer.AXIS_LAYER) ;
                 }
                 else if(target.equals(ConfigInfo.TARGET_SELECTION)){  //selection
                      layer= getLayer(Layer.DYNAMIC_LAYER ) ;

                 }
                 else if(target.equals(ConfigInfo.TARGET_STRING) ){


                     layer=this.getLayer(Layer.BgData_LAYER);
                     layer.setAConfigInfo(key,value);

                     layer=this.getLayer(Layer.TopData_LAYER);
                     layer.setAConfigInfo(key,value);

                 }
                 if(layer!=null) {
                     layer.clearLayer() ;
                     layer.setAConfigInfo(key,value);
                     layer.paintLayer();
                     repaintPlot() ;
                 }
    }

}
